"""
 教学科班主任时长excel切分功能
  @author:zhaoyang
 @Time:2025年9月10日
"""
# -*- coding: utf-8 -*-
import openpyxl
from openpyxl import Workbook
from datetime import datetime

if __name__ == '__main__':
    workbook = openpyxl.load_workbook('D:/projects/jxk/25秋仅直播课-0924.xlsx')
    # 生成新的excel文档
    new_workbook = Workbook()
    new_sheet = new_workbook.active

    sheet = workbook.active
    row = []
    # 迭代工作表中的每一行
    for row in sheet.iter_rows():
        # 列表推导式获取当前行中的所有单元格值
        row_data = [cell.value for cell in row]
        if row_data[18] is not None:
            # 判断逗号
            if ',' in row_data[18]:
                # 根据逗号切割
                time = row_data[18].split(',')
                i = 0
                txt = ""
                for item in time:
                    row_data[18] = "2025年" + item
                    if i == 0:
                        txt = "第一次直播课"
                    if i == 1:
                        txt = "第二次直播课"
                    if i == 2:
                        txt = "第三次直播课"
                    if i == 3:
                        txt = "第四次直播课"
                    if i == 4:
                        txt = "第五次直播课"
                    if i == 5:
                        txt = "第六次直播课"
                    if i == 6:
                        txt = "第七次直播课"
                    if i == 7:
                        txt = "第八次直播课"
                    if i == 8:
                        txt = "第九次直播课"
                    if i == 9:
                        txt = "第十次直播课"
                    row_data[19] = row_data[18].replace("年", "-").replace("月", "-").replace("日", "") + " 19:00" + row_data[8] + txt
                    i = i + 1
                    # 这里可以对每一列数据进行处理
                    # 先处理时间
                    row_data[20] = row_data[18].replace("年", "-").replace("月", "-").replace("日", "") + " 19:00"
                    row_data[21] = row_data[18].replace("年", "-").replace("月", "-").replace("日", "") + " 20:30"
                    new_sheet.append(row_data)
            else:
                row_data[18] = "2025年" + row_data[18]
                row_data[19] = row_data[18].replace("年", "-").replace("月", "-").replace("日", "") + " 19:00" + row_data[8]
                row_data[20] = row_data[18].replace("年", "-").replace("月", "-").replace("日", "") + " 19:00"
                row_data[21] = row_data[18].replace("年", "-").replace("月", "-").replace("日", "") + " 20:30"
                new_sheet.append(row_data)
        else:
            row_data[19] = row_data[8]
            new_sheet.append(row_data)
    # 本地保存test.xlsx
    new_workbook.save("D:/projects/jxk/last-25秋仅直播课-0924.xlsx")
